package com.gonsin.ta.logic.parse.serialize;

import com.gonsin.ta.logic.enums.StackState;
import com.gonsin.ta.logic.parse.condition.Condition;
import com.gonsin.ta.logic.parse.condition.Executable;
import com.gonsin.ta.logic.parse.condition.FutureCondition;
import lombok.Data;

@Data
public class FutureConditionSerial implements TaDeserializable {

    /**
     * THIS 指向的流程id
     */
    private String conditionId;

    private String conditionType = "FUTURE";

    @Override
    public Executable toExecutable(DeserializeContext deserializeContext) {
        if(deserializeContext.getStackState() == StackState.BEFORE_READY){
            FutureCondition notReadyCondition = new FutureCondition();
            notReadyCondition.setConditionId(conditionId);
            return notReadyCondition;
        }
        Condition condition = (Condition) deserializeContext.getStack().get(conditionId);
        FutureCondition readyCondition = new FutureCondition();
        readyCondition.setFutureExecutable(condition);
        return readyCondition;
    }
}
